home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 307.adf / FileIO / CustomList.asm < prev    next >
Assembly Source File  |  1990-01-13  |  15KB  |  461 lines

  1.  ;====Uncomment these directives for MANX asm only!! Advice: Buy a good asm.
  2.  ; far   code ;so that we can use register a4, and no limit on program size.
  3.  ; far   data
  4.  
  5.     SMALLOBJ ;CAPE PC directive. Comment out if not using CAPE
  6.     OBJFILE    "rad:CustomList.o"
  7.  
  8. ; This program opens and utilizes the requester.library in order to use
  9. ; the new SPECIAL_REQ flag. This flag allows us to display a list of
  10. ; strings in a requester with all the features of the FileIO requester.
  11. ; Because version 0 of the library did not support this feature, but version
  12. ; 1.4 now does, we must open the library with version #1. Old applications
  13. ; that do not know about SPECIAL_REQ will still work with this version of
  14. ; the library. It is backward compatible as far as the disk IO features are
  15. ; concerned.
  16.  
  17. ; If running this program from the CLI and you specify any argument on the
  18. ; command (i.e.  1> TestFileIO blort ), then the window will open on a hires
  19. ; screen. You can then see what the requester looks like in hires.
  20.  
  21. ;  For Manx,   ln -o TestFileIO  ManxStartUp.o  main.o  cl32.lib
  22. ;
  23. ;  For Others, Blink StartUp.o main.o amiga.lib NODEBUG to TestFileIO
  24.  
  25.  INCLUDE  "rad:FileIO.i"
  26.  
  27.  ;======Amiga Library routines======
  28.    XREF    _LVOCloseLibrary,_LVOCloseScreen,_LVOCloseWindow,_LVOSetMenuStrip
  29.    XREF    _LVOOpenWindow,_LVOOpenScreen,_LVOOpenLibrary
  30.    XREF    _LVOGetMsg,_LVOReplyMsg,_LVOWait,_LVOMove,_LVOText
  31.    XREF    _LVOSetAPen,_LVOSetBPen,_LVOSetDrMd
  32.  
  33.  ;======From the startup code======
  34.    XREF    _SysBase,_DOSBase
  35.  
  36. LIB_VERSION equ 33
  37.  
  38.    SECTION FileIOTestCode,CODE
  39.  
  40.    XDEF   _main
  41. _main:
  42.     movem.l   d2-d7/a2-a6,-(sp)
  43.     movea.l   _SysBase,a6
  44. ;======Open The Intuition Library=======
  45.     moveq     #LIB_VERSION,d0
  46.     lea       IntuitionName,a1
  47.     jsr       _LVOOpenLibrary(a6)
  48.     lea       _IntuitionBase,a4
  49.     move.l    d0,(a4)+
  50.     beq       C7
  51. ;======Open The Graphics Library========
  52.     moveq     #LIB_VERSION,d0
  53.     lea       GfxName,a1
  54.     jsr       _LVOOpenLibrary(a6)
  55.     move.l    d0,(a4)+
  56.     beq       C6
  57. ;*******Open the "Brand New, Improved, Exciting" Requester library*********
  58.     moveq     #1,d0            ;version #1 please
  59.     lea       RequesterName,a1
  60.     jsr       _LVOOpenLibrary(a6)
  61.     move.l    d0,(a4)+
  62.     beq       C5
  63. ;=====If started from WBench, then don't open a CUSTOM screen
  64.     movea.l   _IntuitionBase,a6
  65.     move.l    52(sp),d0
  66.     beq.s     .9
  67. ;=====If opened from CLI with any argument, then open CUSTOM screen
  68.     subq.l    #2,48(sp)
  69.     bcs.s     .9
  70.     lea       newScreen,a0
  71.     jsr       _LVOOpenScreen(a6)
  72.     lea       newWindow,a0
  73.    ;-----Window's Screen = ScreenPtr
  74.     move.l    d0,30(a0)
  75.     beq.s     .9A             ;If an error, forget the screen!
  76.    ;-----Window's Type = CUSTOMSCREEN
  77.     move.w    #15,46(a0)
  78. ;=========Open the FileIO window==========
  79. .9  lea       newWindow,a0
  80. .9A jsr       _LVOOpenWindow(a6)
  81.     move.l    d0,(a4)+
  82.     beq       C2
  83.     movea.l   d0,a3
  84.    ;---Get Window's RastPort
  85.     move.l    50(a3),(a4)
  86.     lea       ProjectMenu,a1
  87.     movea.l   a3,a0
  88.     jsr       _LVOSetMenuStrip(a6)
  89. ;---Get a FileIO structure
  90. E1  movea.l   _RequesterBase,a6
  91.     jsr       _LVOGetFileIO(a6)
  92.     movea.l   d0,a4
  93.     move.l    d0,d1
  94.     beq       IOe          ;If NULL, then error, so exit this test program.
  95. ;---Set Colors and DrawMode
  96.     moveq     #1,d0
  97.     move.b    d0,FILEIO_DRAWMODE(a4)
  98.     movea.l   RastPort,a2
  99.     movea.l   a2,a1
  100.     movea.l   _GfxBase,a6
  101.     jsr       _LVOSetDrMd(a6)
  102.     moveq     #2,d0
  103.     move.b    d0,FILEIO_PENA(a4)
  104.     movea.l   a2,a1
  105.     jsr       _LVOSetAPen(a6)
  106.     moveq     #0,d0
  107.     move.b    d0,FILEIO_PENB(a4)
  108.     movea.l   a2,a1
  109.     jsr       _LVOSetBPen(a6)
  110. ;====VERY IMPORTANT: Indicate that we want a SPECIAL_REQ==========
  111.     bset.b    #7,(a4)  ;set the SPECIAL_REQ bit of Flags
  112. ;====Set up the XY co-ordinates of where the requester will open====
  113.     moveq     #6,d0
  114.     move.w    d0,FILEIO_X(a4)  ;x position
  115.     moveq     #11,d0
  116.     move.w    d0,FILEIO_Y(a4)  ;y position
  117. ;===========SET UP OUR LIST OF STRINGS==========
  118. ;NOTE: Since our list is initially empty, we don't have to call NewEntryList
  119. ;first, but we will anyway to develop good habits.
  120.     movea.l   _RequesterBase,a6
  121.     movea.l   a4,a1
  122.     jsr       _LVONewEntryList(a6)
  123.     lea       StringAddr,a2
  124.     moveq     #10-1,d7         ;make a list of 10 strings
  125. nxtEN:
  126.     move.l    d7,d1
  127.     addq.w    #1,d1            ;ID = loopcount+1 (i.e. 1 to 10)
  128.     movea.l   a4,a1
  129.     movea.l   (a2)+,a0
  130.     jsr       _LVOAddEntry(a6)
  131.     dbra      d7,nxtEN(pc)
  132. ;---Set up our routine, Information(), as the custom FileIO gadget routine
  133. ;   We don't have to set up these 2 fields, we could leave them 0 in which
  134. ;   case the custom gadget is ignored.
  135.     lea       About,a0
  136.     move.l    a0,FILEIO_TEXT(a4)
  137.     lea       Information,a0
  138.     move.l    a0,FILEIO_ROUTINE(a4)
  139. ;====Create a mask of the Window's UserPort's mp_Sigbit=====
  140. E3  movea.l   86(a3),a0
  141.     move.b    15(a0),d0
  142.     moveq     #0,d7
  143.     Bset.l    d0,d7
  144. ;=====Get the message that arrived at our UserPort====
  145. E4  movea.l   86(a3),a0
  146.     movea.l   _SysBase,a6
  147.     jsr       _LVOGetMsg(a6)
  148.     move.l    d0,d1
  149.     bne.s     E7
  150. ;===Check if we are ready to exit the program=====
  151. E5  Btst.b    #0,Quit
  152.     beq       E15
  153. ;----Print out "Click Mouse to start demo....
  154.     movea.l   RastPort,a2
  155.     moveq     #5,d0
  156.     moveq     #75,d1
  157.     movea.l   a2,a1           ;our window's RastPort
  158.     move.l    a6,-(sp)        ;save _SysBase
  159.     movea.l   _GfxBase,a6
  160.     jsr       _LVOMove(a6)
  161.     moveq     #36,d0          ;# of bytes to output.
  162.     lea       Click,a0
  163.     movea.l   a2,a1
  164.     jsr       _LVOText(a6)
  165.     movea.l   (sp)+,a6        ;restore _SysBase
  166. ;===Wait for a message sent to our Window (from Intuition)===
  167. E6  move.l    d7,d0
  168.     jsr       _LVOWait(a6)
  169.     bra.s     E4
  170. ;====Copy all the info we want from the IntuiMessage====
  171. E7  movea.l   d0,a1
  172.     lea       20(a1),a0  ;get the address of the first field to copy.
  173.     move.l    (a0)+,d6   ;Copy the Class field to d6
  174.     move.w    (a0)+,d5   ;Copy the Code field to d5
  175.     move.w    (a0)+,d4   ;Copy the qualifier field to d4
  176.     movea.l   (a0)+,a2   ;Copy the IAddress field to a2
  177.     move.w    (a0)+,d3   ;Copy MouseX position to d3
  178.     move.w    (a0)+,d2   ;Copy MouseY position to d2
  179. ;====Now reply to the message so Intuition can dispose of it
  180. E8  ;Address of the message is in a1.
  181.     jsr       _LVOReplyMsg(a6)
  182. ;========switch (class)=========
  183.     Bclr.l    #9,d6  ;CLOSEWINDOW
  184.     bne.s     CW
  185.     Bclr.l    #8,d6  ;MENUPICK
  186.     bne.s     MU
  187.     Bclr.l    #3,d6  ;MOUSEBUTTONS
  188.     beq       E4
  189. ;---Make sure that it's an UP select if MOUSEBUTTONS
  190.     subi.b    #$68,d5
  191.     beq       E4     ;ignore down
  192. ;===The FOLLOWING ROUTINE IS OUR TEST CALL. WHEN THE USER IS DONE (in FileIO lib)
  193. ;===HE WILL SELECT EITHER THE CANCEL OR OK! GADGET. IF CANCEL, TestFileIO
  194. ;===DOES NOTHING. IF OK!, TestFileIO JUSTS PRINTS THE SELECTED STRING.
  195. E2  bsr     TestFileIO
  196.     bra     E4
  197. ;=========case CLOSEWINDOW:============
  198. CW  Bclr.b    #0,Quit
  199.     bra       E4
  200. ;=========case MENUPICK:==============
  201.   ;------Determine which item
  202. MU lsr.w   #5,d5         ;Shift the item # bits into lowest bits of reg.
  203.    andi.w  #$3F,d5       ;Isolate the Item # from the Menu and subitem #.
  204.    bne     E4
  205. ;---Set MULTIPLE_FILES
  206.    bchg.b  #MULTIPLE_FILES,1(a4)
  207.    bra     E4
  208. ;======if an error, indicate NO_MEMORY. This is a FileIO routine
  209. ;======and is callable even if GetFileIO() fails
  210. IOe movea.l   a3,a0
  211.     moveq     #0,d0
  212.     movea.l   _RequesterBase,a6
  213.     jsr       _LVOAutoFileMessage(a6)
  214. ;========NOW BEGINS OUR EXIT ROUTINE=========
  215.  ;ReleaseFileIO will free our list of strings
  216. E15 movea.l   a4,a1                ;If the pointer to FileIO was NULL, then
  217.     movea.l   _RequesterBase,a6    ;ReleaseFileIO just returns, so it's safe to
  218.     jsr       _LVOReleaseFileIO(a6) ;always release any return value of GetFileIO.
  219. ;=====Close the Window and Screen======
  220. C1  movea.l   _IntuitionBase,a6
  221.     movea.l   a3,a0
  222.     jsr       _LVOCloseWindow(a6)
  223. C2  move.l    ScreenPtr,d0
  224.     beq.s     C3            ;check if we specified a screen
  225.     movea.l   d0,a0
  226.     ; _IntuitionBase in a6
  227.     jsr       _LVOCloseScreen(a6)
  228. ;=====Close Whichever Libs are Open (_SysBase in a6 for ALL calls)=====
  229. C3  movea.l  _SysBase,a6
  230.     movea.l  _RequesterBase,a1
  231.     jsr      _LVOCloseLibrary(a6)
  232. C5  movea.l  _GfxBase,a1
  233.     jsr      _LVOCloseLibrary(a6)
  234. C6  movea.l  _IntuitionBase,a1
  235.     jsr      _LVOCloseLibrary(a6)
  236. C7  movem.l  (sp)+,d2-d7/a2-a6
  237.     rts
  238.  
  239. ;*******************************************
  240. ; This just calls the DoFileIO library routine and displays a msg on return.
  241. ; (GetFileIO must have been called with success first).
  242. ; The DoFileIO routine returns -1 if the user selected CANCEL, -2 if the
  243. ; library is in use by another task, or returns non-zero if OK! was selected.
  244. ; At this point, if the user selected OK, our FILEIO_FILENAME buffer will
  245. ; contain the selected string and FILEIO_FILESIZE will be the ID.
  246. ;
  247. ;   TestFileIO(FileIO, window)
  248. ;                a4      a3
  249.  
  250. typename:
  251. ;--This shows what would happen (automatically) if the lib was in use on a
  252. ;  call to DoFileIO(), or the requester couldn't open.
  253.  
  254. .error:
  255.         lea        errmsg,a0
  256. prt    move.l    a0,d0
  257.         movea.l    a3,a0
  258.         jsr        _LVOAutoMessage(a6)
  259.         moveq        #0,d0
  260.         rts
  261. .can    lea        cancel,a0
  262.         bra.s        prt
  263. .inuse:
  264.         lea        inuse,a0
  265.         bra.s        prt
  266.  
  267.    XDEF TestFileIO
  268. TestFileIO:
  269.         movea.l    _RequesterBase,a6
  270.     ;---DoFileIO(FileIO, window)
  271.         movea.l    a3,a1
  272.         movea.l    a4,a0
  273.         jsr        _LVODoFileIO(a6)
  274.         move.l    d0,d1
  275.         beq.s        .error
  276. ;Must have been an error if returned 0. If we were using DoFileIOWindow(),
  277. ;the window might not have opened. Or the requester might not have opened.
  278. ;We could check the FileIO's ERRNO field to see what the specific error was.
  279.         addq.l    #1,d1
  280.         beq.s        .can        ;If -1, user must have selected CANCEL
  281.         addq.l    #1,d1
  282.         beq.s    .inuse    ;If -2, the library was in use
  283.  ;---AutoMessage(string, window)  Display our chosen string.
  284.         ;Filename buffer address in d0
  285.         movea.l    a3,a0
  286.         jsr        _LVOAutoMessage(a6)
  287.  ;---If ID = -1 then user must have typed a string not in the list
  288.         move.l    FILEIO_FILESIZE(a4),d0  ;this is the ID of the chosen field
  289.         bpl.s        out1
  290.         movea.l    a3,a0
  291.         lea        NotIn,a1
  292.         move.l    a1,d0
  293.         jsr        _LVOAutoMessage(a6)
  294.     ;---Did our custom routine end the requester?
  295. out1    moveq        #ERR_APPGADG,d0
  296.         sub.b        FILEIO_ERRNO(a4),d0
  297.         bne.s        out2
  298.         movea.l    a3,a0
  299.         lea        AppCan,a1
  300.         move.l    a1,d0
  301.         jsr        _LVOAutoMessage(a6)
  302.     ;---If MULTIPLE_FILES, display all selected entries
  303. out2    btst.b   #MULTIPLE_FILES,1(a4)
  304.         beq.s    out3
  305.         clr.l    -(sp)      ;zero our PTR to a FileEntry
  306. morFL    movea.l  sp,a0
  307.         movea.l  a4,a1
  308.         jsr      _LVORetrieveEntry(a6)
  309.         move.l   d0,d1
  310.         beq.s    last
  311.         movea.l  d0,a0
  312.         move.l   8(a0),d0   ;get the Entry structure
  313.         addq.l   #5,d0      ;get the EntryString address
  314.         movea.l  a3,a0
  315.         jsr      _LVOAutoMessage(a6)
  316.         bra.s    morFL
  317. last    addq.l   #4,sp
  318. out3    moveq        #1,d0
  319.         rts
  320.  
  321. ;=====================================================================
  322. ; Our routine for the custom FileIO gadget. Lib passes our FileIO in a2
  323. ; and Window in a3. This returns the BOOL value from AutoPrompt3 so that
  324. ; if the user selects YES (TRUE) the requester ends.
  325.  
  326.    XDEF Information
  327. Information:
  328.     movem.l  a2/a3,-(sp)
  329.     movea.l  a3,a0
  330.     lea      Msg1,a1
  331.     lea      Msg2,a2
  332.     lea      Msg3,a3
  333.     movea.l  _RequesterBase,a6
  334.     jsr      _LVOAutoPrompt3(a6)
  335.     movem.l  (sp)+,a2/a3
  336.     rts
  337.  
  338.   ; SECTION MainData,DATA  ;Not needed for CAPE PC relative addressing!!
  339.  
  340.    XDEF _IntuitionBase,_GfxBase,ScreenPtr
  341.    XDEF _RequesterBase
  342.  ;must be in this order
  343. _IntuitionBase dc.l 0
  344. _GfxBase       dc.l 0
  345. _RequesterBase dc.l 0
  346. window         dc.l 0
  347. RastPort       dc.l 0
  348.  
  349.    XDEF   newScreen
  350. newScreen:
  351.    dc.w   0,0         ;LeftEdge, TopEdge
  352.    dc.w   640,400     ;Width, Height
  353.    dc.w   2           ;Depth
  354.    dc.b   0,1         ;Detail, Block pens
  355.    dc.w   -32764      ;ViewPort Modes HIRES|LACE (must set/clr HIRES as needed)
  356.    dc.w   15          ;CUSTOMSCREEN
  357.    dc.l   TextAttr    ;Font
  358.    dc.l   ScrTitle
  359.    dc.l   0           ;Gadgets
  360.    dc.l   0           ;CustomBitmap
  361.  
  362.    XDEF   newWindow
  363. newWindow:
  364.           dc.w   30,30
  365.           dc.w   306,145
  366.           dc.b   0,1
  367.  ;IDCMP = MOUSEBUTTONS|CLOSEWINDOW|MENUPICK
  368.           dc.l   $308
  369.  ;WindowFlags = WINDOWDRAG|WINDOWDEPTH|SMART_REFRESH|ACTIVATE|WINDOWSIZE
  370.  ;(no FOLLOWMOUSE allowed as that messes up the requester when using
  371.  ;DoFileIO(). If you need FOLLOWMOUSE, then use DoFileIOWindow() to open
  372.  ;the req in its own window.)
  373.           dc.l   $100F
  374.           dc.l   0
  375.           dc.l   0
  376.           dc.l   WINTITLE
  377. ScreenPtr dc.l   0
  378.           dc.l   0
  379.           dc.w   306,145
  380.           dc.w   600,240
  381.           dc.w   1         ;WBENCHSCREEN
  382.  
  383. ;==========THE PROJECT MENU===========
  384.  
  385. ProjectMenu:
  386.    dc.l 0
  387.    dc.w 0,0
  388.    dc.w 90,0
  389.    dc.w 1
  390.    dc.l ProjectTitle
  391.    dc.l ExtItem
  392.    dc.w 0,0,0,0
  393.  
  394.  ;These are MenuItem structures for the preceding Menu Structure.
  395. ExtItem   dc.l 0
  396.           dc.w 0,0
  397.           dc.w 200,10
  398.           dc.w $5F
  399.           dc.l 0
  400.           dc.l MultiText
  401.           dc.l 0
  402.           dc.b 'M'
  403.           dc.b 0
  404.           dc.l 0
  405.           dc.w 0
  406. MultiText dc.b 0,1,1,0
  407.           dc.w 19,0
  408.           dc.l TextAttr,MultiString,0
  409.  
  410. TextAttr:        ;Topaz 8 is a ROM font so doesn't need to be opened
  411.    dc.l   FONTNAME
  412.    dc.w   8      ;TOPAZ_EIGHTY
  413.    dc.b   0,0
  414.  
  415. StringAddr:
  416.    dc.l  Ten
  417.    dc.l  Nine
  418.    dc.l  Eight
  419.    dc.l  Seven
  420.    dc.l  Six
  421.    dc.l  Five
  422.    dc.l  Four
  423.    dc.l  Three
  424.    dc.l  Two
  425.    dc.l  One
  426.  
  427. Ten   dc.b 'Ten',0
  428. Nine  dc.b 'Nine',0
  429. Eight dc.b 'Eight',0
  430. Seven dc.b 'Seven',0
  431. Six   dc.b 'Six',0
  432. Five  dc.b 'Five',0
  433. Four  dc.b 'Four',0
  434. Three dc.b 'Three',0
  435. Two   dc.b 'Two',0
  436. One   dc.b 'And this is One',0
  437.  
  438. Quit dc.b 1  ;When this is a 0, the user wants to exit.
  439.  
  440. ScrTitle            dc.b 'Example FileIO Program Screen',0
  441. WINTITLE            dc.b 'Example FileIO Program Window',0
  442. Click                dc.b 'Click mouse for demo or CLOSEWINDOW.',0
  443. IntuitionName    dc.b 'intuition.library',0
  444. DOSName            dc.b 'dos.library',0
  445. GfxName            dc.b 'graphics.library',0
  446. RequesterName    dc.b 'requester.library',0
  447. FONTNAME            dc.b 'topaz.font',0
  448. errmsg            dc.b 'Error in opening the requester',0
  449. cancel            dc.b 'The CANCEL gadget was selected',0
  450. inuse                dc.b 'Another task using the requester',0
  451. About                dc.b '   About',0
  452. Msg1                dc.b 'An example of SPECIAL_REQ',0
  453. Msg2                dc.b 'by Jeff Glatt',0
  454. Msg3                dc.b 'dissidents',0
  455. NotIn                dc.b 'This string is not in the list.',0
  456. AppCan            dc.b 'Cancelled by the custom gadget.',0
  457. MultiString        dc.b 'Multi File',0
  458. ProjectTitle    dc.b 'Project',0
  459.  
  460.    END
  461.